package com.yang.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yang.model.BaseResult;
import com.yang.model.PageResult;
import com.yang.model.Role;
import com.yang.model.User;
import com.yang.service.RoleService;

@Controller
@RequestMapping("role")
public class RoleController {
	
	private RoleService roleService;
	
	@RequestMapping("role")
	public String role() {		
		return "role/role";
	}
	
	 @RequestMapping("queryTableData")
	    @ResponseBody
	    public BaseResult<Object> queryTableData( Integer currenrPage,Integer pageSize,String search_value) {			
	    	BaseResult<Object> result =new BaseResult<>();
	    	Map<String, Object> map =new HashMap<>();
	    	map.put("currenrPage", (currenrPage-1)*pageSize);
	    	map.put("pageSize", pageSize);
	    	map.put("search_value", search_value);
	    	List<Role> roles = roleService.queryRoles(map);
	    	List<Role> allRolles = roleService.queryAllRoles(map);
	    	
	    	PageResult<Role> pageResult=new PageResult<>();
	    	pageResult.setCurrentPage(currenrPage);
	    	pageResult.setPageSize(pageSize);
	    	pageResult.setPageTotal(allRolles.size()%pageSize==0?allRolles.size()/pageSize:allRolles.size()/pageSize+1);
	    	pageResult.setData(roles);
	    	
	    	if (roles !=null) {				
	    		result.setSuccess(true);
	    		result.setData(pageResult);
			}else {
				result.setSuccess(false);
			}
	    	 	    	
	    	return result;
		}

}
